package ${baseInfo.packageName};

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${tableClass.fullClassName};
import ${serviceInterface.packageName}.${serviceInterface.fileName};
import ${mapperInterface.packageName}.${mapperInterface.fileName};
<#if baseService??&&baseService!="">
import ${baseService};
    <#list baseService?split(".") as simpleName>
        <#if !simpleName_has_next>
            <#assign serviceSimpleName>${simpleName}</#assign>
        </#if>
    </#list>
</#if>
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import ${domainCmd.packageName}.${tableClass.shortClassName}Cmd;
import ${domainUpd.packageName}.${tableClass.shortClassName}Upd;
import ${domainQry.packageName}.${tableClass.shortClassName}Qry;
import ${domainVo.packageName}.${tableClass.shortClassName}Vo;

/**
* @author ${author!}
* @description 针对表【${tableClass.tableName}<#if tableClass.remark?has_content>(${tableClass.remark!})</#if>】的数据库操作Service实现
* @createDate ${.now?string('yyyy-MM-dd HH:mm:ss')}
*/
@Service
public class ${baseInfo.fileName} extends ServiceImpl<${mapperInterface.fileName}, ${tableClass.shortClassName}>
    implements ${serviceInterface.fileName}{


    @Autowired
    private ${tableClass.shortClassName}Mapper ${tableClass.shortClassName}Mapper;

    @Override
    public ${tableClass.shortClassName}Vo findOne(Long id) {
        ${tableClass.shortClassName} domain = this.getById(id);
        return this.domainToVo(domain);
    }

    @Override
    public Boolean updateOne(${tableClass.shortClassName}Upd upd) {
        ${tableClass.shortClassName} domain = this.updToDomain(upd);
        return this.updateById(domain);
    }

    @Override
    public IPage<${tableClass.shortClassName}Vo> findPage(${tableClass.shortClassName}Qry qry) {

        Page<${tableClass.shortClassName}> page = new Page<>(qry.getPageNum(), qry.getPageSize());
        Page<${tableClass.shortClassName}> resultPage = baseMapper.selectPage(page, null);

        return resultPage.convert(domain -> this.domainToVo(domain));
    }

    @Override
    public Boolean createOne(${tableClass.shortClassName}Cmd cmd) {
        ${tableClass.shortClassName} domain = this.cmdToDomain(cmd);
        return this.save(domain);
    }

    @Override
    public Boolean deleteOne(Long id) {
        return this.removeById(id);
    }

    private ${tableClass.shortClassName} cmdToDomain(${tableClass.shortClassName}Cmd cmd){
    ${tableClass.shortClassName} domain = new ${tableClass.shortClassName}();
    <#list tableClass.allFields as field>
    domain.set${field.fieldName?cap_first}(cmd.get${field.fieldName?cap_first}());
    </#list>
        return domain;
    }

    private ${tableClass.shortClassName} updToDomain(${tableClass.shortClassName}Upd upd){
    ${tableClass.shortClassName} domain = new ${tableClass.shortClassName}();
    <#list tableClass.allFields as field>
    domain.set${field.fieldName?cap_first}(upd.get${field.fieldName?cap_first}());
    </#list>
    return domain;
    }

    private ${tableClass.shortClassName}Vo domainToVo(${tableClass.shortClassName} domain){
    ${tableClass.shortClassName}Vo vo = new ${tableClass.shortClassName}Vo();
    <#list tableClass.allFields as field>
    vo.set${field.fieldName?cap_first}(domain.get${field.fieldName?cap_first}());
    </#list>
    return vo;
    }

}




